@extends('layouts.header')
@section('style')
    label.error {
    position: absolute;
    right: 0px;
    top: 18px;
    color: #ef392b;
    font-size: 12px;
    }

    input[type=text] {
    /* width:50px; */
    text-align: center
    }

    .t-a-l {
    text-align: left !important;
    padding-left: 3px !important;
    }

    .col-1, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-10, .col-11, .col-12, .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 {
    padding-left: 0px;
    padding-right: 0px;
    /* border:solid 1px #ef392b ; */
    }

    @media (max-width: 767px) {
    .form-horizontal .form-label {
    text-align: right;
    }
    }

    .row {
    margin-left: 0px;
    margin-right: 0px;
    }

    .form .row {
    margin-top: 7px;
    }
@endsection
@section('title','试验结果')
@section('content')
<article class="page-container">
    <div class="mb-15">
        <div class="f-l" style="width:50%">
            <b>　条形码：</b><span style="color:#ff0000;font-size:18px;">{{ $sample_info_data->bar_code }}</span><br>
            @if(DB::table('setting')->where('id', '1')->value('enable_tool_ID'))
                <b>工器具ID：</b><span style="color:red;">{{ $sample_info_data->gqj_ID }}</span><br>
            @endif
            <b>样品名称：</b>{{ $gaiyao_data->tool_name }}<br>
            <b>检验标准：</b>{{ $gaiyao_data->std_num }}<br>
            <b>额定电压：</b>{{ $gaiyao_data->voltage }}<br>
            <b>　　分类：</b>{{ $gaiyao_data->class }}<br>
            <b>样品状态：</b>{{ $sample_info_data->sample_status }}<br>
            <b>内 网 ID：</b>{{ $sample_info_data->third_id }}<br>
            <b>风控样品名称：</b>{{ $third_info?$third_info->third_tool_name:''}}<br>
        </div>
        <div class="f-l" style="width:50%">
            <b>　自编号：</b>{{ $sample_info_data->self_num }}<br>
            <b>生产厂家：</b>{{ $sample_info_data->manufacturer }}<br>
            <b>生产日期：</b>{{ $sample_info_data->production_date }}<br>
            <b>规格型号：</b>{{ $sample_info_data->guige_xinghao }}<br>
            <b>　　商标：</b>{{ $sample_info_data->brand }}<br>
            <b>使用周期：</b>{{ $cycle }}年<br>
            <b>　　备注：</b>{{ $sample_info_data->remark }}<br>
        </div>
        <div style="clear:both"></div>
    </div>

    <div class="cl pd-5 bg-1 bk-gray mt-10 mb-10">
        {{-- <span class="l">
            <b>条形码：</b><input type="text" class="input-text" value="" placeholder="后三位" id="bar-code" style="width:60px">
        </span>
        <span class="l ml-10">
            <a class="btn btn-primary radius" href="javascript:;" onclick="goto_jump()">跳转</a>
        </span> --}}
        <span class="l ml-20">
            <a class="btn radius btn-primary" href="javascript:;" onclick="layer_show('温湿度气压计','temHuiPreIndex')">同步设备环境</a>
        </span>
        <span class="r mr-10">
                @if ($sample_id_next)
                <a class="btn btn-primary radius" href="javascript:;" onclick="goto_pre_next({{ $sample_id_next }})">下一个</a>
            @else
                <a class="btn radius disabled" href="javascript:;">下一个</a>
            @endif
        </span>
        <span class="r mr-20">
                @if ($sample_id_pre)
                <a class="btn btn-primary radius" href="javascript:;" onclick="goto_pre_next({{ $sample_id_pre }})">上一个</a>
            @else
                <a class="btn radius disabled" href="javascript:;">上一个</a>
            @endif
        </span>
    </div>

    <ul id="Huifold" class="Huifold">
        @foreach ($items_data as $key=>$val)
            <form autocomplete="off" id="form-@php echo $key; @endphp">
                {{csrf_form_field()}}
                <li class="item">
                    <h4 @if(config('constant.app_name') === 'ChongQingYuDian') onclick="getBindItem(this,{{$val->id}})" @endif>
                        {{ $val->name }}
                        @if ($val->res === 1)
                            <span class="badge badge-success radius">符合</span>
                        @elseif ($val->res === 0)
                            <span class="badge badge-danger radius">不符合</span>
                        @endif
                        <b>+</b>
                    </h4>
                    <div class="info">
                        @if($bindItem)
                        <span class="btn btn-primary radius size-MINI toBindItemEle" data-code="" onclick="toBindItem(this,{{$val->id}})">绑定项目</span>
                            <br>
                        @endif
                        <b style="color:blue">检验标准</b>&emsp;
                        @php
                            $data_std_tool_item_rel = DB::table('a_std_tool_item_rel')->select('id','jishu_yaoqiu','station_ids')->where([
                                ['std_id','=',$gaiyao_data->std_id],
                                ['tool_id','=',$gaiyao_data->tool_id],
                                ['testitem_id','=',$val->item_id]
                            ])->first();
                            if($data_std_tool_item_rel){
                            	$yaoqiu = $data_std_tool_item_rel->jishu_yaoqiu;
                                $std_tool_item_rel_id = $data_std_tool_item_rel->id;

                                $key_condition = DB::table('a_condition_key')->select('id','key','unit')->where('std_tool_item_rel_id','=',$std_tool_item_rel_id)->orderBy('sort')->get();

                                $stdAry = [];
                                foreach ($key_condition as $k => $v) {
                                    $val_condition = DB::table('a_condition')->where('condition_key_id','=',$v->id)->whereIn('vol_class_id',[0,$gaiyao_data->vol_id,$gaiyao_data->class_id])->pluck('val')->toArray();
                                    $val_condition = implode($val_condition,' / ');
                                    $stdAry[$v->key] = $val_condition;
                                    echo "<b>{$v->key}：</b>$val_condition{$v->unit}&emsp;";
                                }

                                echo "<b>要求：</b>$yaoqiu";
                                echo "<hr style='margin:5px;background-color:#ddd;height:1px;width:100%;border:none;'>";
                            }

                        @endphp

                        <input type="hidden" name="item_id" value="{{ $val->id }}">{{-- 这里的item_id指的是a_item_data表的id --}}
                        <input type="hidden" name="cycle" value="{{ $cycle }}">{{-- 周期 --}}
                        <div class="mb-10">
                            <b class="c-blue">分配时间</b>&emsp; {{$val->allot_time ? $val->allot_time : '/'}}
                        </div>
                        <b class="c-blue">原始记录</b>&emsp;<br>
                        <div class="" style="margin-left: -15px;margin-right: -15px;">
                            {{--将外观检查的温湿度大气压隐藏--}}
                            <div class="f-l form form-horizontal @if($val->item_id===61) hidden @endif" style="width:39%;border-right:1px dotted #ddd">
                                <div class="row cl">
                                    <label class="form-label col-xs-4"><b>天气：</b></label>
                                    <div class="formControls col-xs-5">
                                        <select class="select2 input-text" name="wea">
                                            <option value="{{$val->wea ?:cache('wea')}}" selected>{{$val->wea ?:cache('wea')}}</option>
                                            @foreach($wea_stat as $wea)
                                                <option value="{{$wea}}">{{$wea}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                                <div class="row cl">
                                    <label class="form-label col-xs-4"><b>大气压力：</b></label>
                                    <div class="formControls col-xs-5">
                                        <input type='text' class="input-text" name="pressure" value='{{$val->pressure}}'>
                                    </div>
                                    <label class="form-label t-a-l col-xs-3">kPa</label>
                                </div>
                                <div class="row cl">
                                    <label class="form-label col-xs-4"><b>环境温度：</b></label>
                                    <div class="formControls col-xs-5">
                                        <input type='text' class="input-text" name="temp" value='{{$val->temp}}'>
                                    </div>
                                    <label class="form-label t-a-l col-xs-3">℃</label>
                                </div>
                                <div class="row cl">
                                    <label class="form-label col-xs-4"><b>相对湿度：</b></label>
                                    <div class="formControls col-xs-5">
                                        <input type='text' class="input-text" name="hum" value='{{$val->hum}}'>
                                    </div>
                                    <label class="form-label t-a-l col-xs-3">%</label>
                                </div>
                            </div>

                            <div class="f-l form form-horizontal" style="width:60%;">

                                @php
                                if(isset($std_tool_item_rel_id)){
                                    $key_data = DB::table('a_testdata_key')->select('id','data_key','data_unit','upload_key','upload_unit','upload_bei')->where('std_tool_item_rel_id','=',$std_tool_item_rel_id)->orderBy('sort')->get();

                                    foreach ($key_data as $k => $v) {
                                        // $str = 'val' . $k;
                                        // echo '<span>' . $v->data_key . "<input type='text' name='$str' value='{$val->$str}' >" . $v->data_unit . '&emsp;' . '</span>';
                                        $input_data = DB::table('a_input_data')->where([
                                            ['sample_info_id','=',$sample_info_data->id],
                                            ['testdata_key_id','=',$v->id]
                                        ])->first();
                                        if ($input_data) {
                                            $input_data->val = is_null($input_data->val)? explode('～',(isset($stdAry[$v->data_key]) ? $stdAry[$v->data_key] : '') )[0] : $input_data->val;
    $html = <<<eof
        <div class="row cl data-key-val">
            <label class="form-label col-xs-4"><b>{$v->data_key}：</b></label>
            <div class="formControls col-xs-5">
eof;
$inputvalAry = explode('.',$input_data->val);
$imgExtAry = ['jpg','png','jpeg'];
if(isset($inputvalAry[1]) && in_array($inputvalAry[1],$imgExtAry)){
    $html .= <<<eof
                <input type='text' class="input-text hidden" name="val[{$input_data->id}]" value='{$input_data->val}'>
                <a href="{$input_data->val}" target="_blank"><img onclick="" class="formControls col-xs-12 thumbnail" src="{$input_data->val}"></a>
eof;
}else{
    $html .= <<<eof
                <input type='text' class="input-text" name="val[{$input_data->id}]" value='{$input_data->val}'>
eof;
}
    $html .= <<<eof
            </div>

            <label class="form-label t-a-l col-xs-3">{$v->data_unit}
        </div>
eof;
                                        }else{
                                            //如果记录不存在，则插入
                                            $input_data_id = DB::table('a_input_data')->insertGetId(
                                                ['sample_info_id' => $sample_info_data->id, 'testdata_key_id' => $v->id]
                                            );
                                            $html = <<<eof
                                                    <div class="row cl">
                                                        <label class="form-label col-xs-4"><b>{$v->data_key}：</b></label>
                                                        <div class="formControls col-xs-5">
                                                            <input type='text' class="input-text" name="val[$input_data_id]" value=''>
                                                        </div>
                                                        <label class="form-label t-a-l col-xs-3">{$v->data_unit}</label>
                                                    </div>
eof;
                                        }
                                        echo $html;
                                    }
                                }
                                @endphp
                            </div>
                            <div class="form form-horizontal" style="width:39%;">
                                <div class="row cl">
                                    <label class="form-label col-xs-4"><b>备注/不符合现象描述：</b></label>
                                </div>
                            </div>
                            <div class="form form-horizontal" style="width:100%;">
                                <div class="row cl">
                                    <div class="formControls col-xs-12">
                                        <textarea class="textarea" name="remark">{{$val->remark}}</textarea>
                                    </div>
                                </div>
                            </div>

                            <div style="clear:both"></div>
                        </div>
                        <hr style='margin:5px;background-color:#ddd;height:1px;width:100%;border:none;'>
{{--                        设备管理--}}
                        <div class="@if($val->item_id===61) hidden @endif">
                            <b style="color:blue">设备列表</b>&emsp;<span class="ml-20"><a class="btn btn-primary radius size-MINI" onclick="checkDev({{$val->item_id}},this)"><b>选择设备</b></a></span><br>
                            <div class="mb-10" style="maergin-left: -15px;margin-right: -15px;">
                                <div class="row cl">
                                    <label class="form-label col-xs-2"></label>
                                    <div class="formControls col-xs-10">
                                        <table class="table table-border table-bordered table-hover table-bg table-responsive ml-10" >
                                            <thead>
                                            <tr>
                                                <th>名称</th>
                                                <th>编号</th>
                                                <th class="text-c">有效期</th>
                                            </tr>
                                            </thead>
@php
$stdIds = $val->station_ids;
if(!$stdIds && $data_std_tool_item_rel){
   $stdIds = $data_std_tool_item_rel->station_ids;
   if($stdIds){
       echo '<span class="def-tip" style="color:red;">以下为默认的设备列表，请及时保存！</span>';
   }
}
$stdIdStr = $stdIds;
$stdIds = explode(',',$stdIdStr);
$stations = DB::table('a_station')->whereIn('id',$stdIds)->get();
@endphp
                                            <input type="hidden" name="old_station_ids" value="{{$stdIdStr}}">
                                            <input id="station_ids_{{$val->item_id}}" type="hidden" name="station_ids" value="{{$stdIdStr}}">
                                            <tbody id="tbody_{{$val->item_id}}">
                                            @foreach($stations as $item)
                                                <tr>
                                                    <td>{{$item->name}}</td>
                                                    <td>{{$item->dev_num}}</td>
                                                    <td class="text-c">{{$item->trace_exp_date ? $item->trace_exp_date : '/'}}</td>
                                                </tr>
                                            @endforeach
                                            </tbody>
                                        </table>
                                    </div>
                                </div>

                                <div style="clear:both"></div>
                            </div>
                        </div>
                        <b style="color:blue">试验日期</b>&emsp;
                        <input type="text" name="utime" readonly value="{{date("Y-m-d",$val->utime ? strtotime($val->utime) : time())}}" onfocus="WdatePicker({})" class="input-text Wdate" style="width:180px">

                        <div class="mt-10">
                            <span class="r">
                                &emsp;<input type="submit" value="保 存" class="btn btn-primary radius @if($val->commit > 0) disabled @endif">
                            </span>
                            <span class="r mr-30">
                                <b style="color:blue">检测结果：</b>
                                <select name="res" style="height:30px;width:78px">
                                    <option value="1">符合</option>
                                    <option value="0">不符合</option>
                                    <option value="3">/</option>
                                </select>
                            </span>
                            @csrf
                        </div>
                        <div style="clear:both"></div>
                    </div>
                </li>
            </form>
        @endforeach
    </ul>

</article>

<script>
    var bindItems = @json($bindItem),index2;
    $(function () {
        $("#Huifold").Huifold({
            titCell: '.item h4',
            mainCell: '.item .info',
            type: 1,
            trigger: 'click',
            className: "selected",
            // speed:"fast",//"slow" | "normal" | "fast"
            speed: 0
        });

        //默认展开第一个
        // $("#Huifold li").first().find('h4').trigger("click");

        // $("input:submit").click(function(){
        //     $("form").removeClass("form");
        // 	$(this).closest("form").addClass("form");
        // });

        @if ($commit >=1)
        $("input:text").attr("disabled", true);
        $("textarea").attr("disabled", true);
        $("select").attr("disabled", true);
        $("input:submit").addClass("disabled").removeClass("btn-primary");
                @endif

        @foreach ($items_data as $key=>$val)
        $('#form-@php echo $key; @endphp').validate({
            rules: {
                utime: {
                    required: true,
                },
                wea: {
                    required: true,
                    notSpace: true,
                },
                temp: {
                    required: true,
                    number: true,
                    range: [-40, 60],
                },
                hum: {
                    required: true,
                    number: true,
                    range: [1, 100],
                },
                pressure: {
                    required: true,
                    number: true,
                    range: [1, 150],
                },
            },
            // onkeyup:false,
            // focusCleanup:false,
            success: "valid",
            submitHandler: function (form) {
                let formid = this.currentForm.id;
                let res = $.trim($('#' + formid + ' li h4 span').text());
                if (res !== '') {
                    let index = layer.confirm('确定要覆盖当前结果吗？', function () {
                        ajaxform(form);
                        layer.close(index);
                    });
                } else {
                    ajaxform(form);
                }

                function ajaxform(form) {
                    $(form).ajaxSubmit({
                        type: 'post',
                        url: "",//自己提交给自己可以不写url
                        //beforeSend  beforeSubmit

                        beforeSend: function () {
                            //0.4透明度 白色遮罩
                            index2 = layer.load(2, {shade: [0.3, '#fff']});
                        },
                        complete: function () {
                            layer.close(index2);
                        },
                        success: function (data) {
                            //判断修改结果
                            if (data === '1') {
                                window.location.reload();//刷新
                                parent.table_reload(0);//0停留在当前页，1回到第一页
                                parent.layer.msg('保存成功!', {icon: 1, time: 1000});
                                // layer_close();//关闭自己
                            } else if (data === '2') {
                                window.location.reload();//刷新
                                parent.layer.msg('该样品已提交!', {icon: 2, time: 3000});
                            } else {
                                if (data == '0'){
                                    layer.msg('操作失败!', {icon: 2, time: 2000});
                                }else{
                                    layer.msg(data, {icon: 2, time: 2000});
                                }
                            }
                        },
                        error: function (data) {
                            ajax_error(data);
                        }
                    });
                }
            }
        });
        @endforeach

        /* 因天气获取接口有变动，暂时先注释掉 */
        /* 获取实时天气 */
        /*  $.ajax({
             type: 'GET',
             url: '/{{config('constant.name_admin')}}/myapi/getWeather',
        success: function(data){
            $("input[name='wea']").each(function () {
                if ($(this).val()==='') {
                    $(this).val(data.wea);
                }
            });
            $("input[name='pressure']").each(function () {
                if ($(this).val()==='') {
                    $(this).val(data.pressure);
                }
            });

        },
        error:function(data) {
            ajax_error(data);
        },
    });	 */

        /* 去缓存获取天气 */
        $("input[name='wea']").each(function () {
            if ($(this).val() === '') {
                $(this).val('{{ Cache::get('wea', '') }}');
            }
        });
        /* 去缓存获取气压 */
        $("input[name='pressure']").each(function () {
            if ($(this).val() === '') {
                $(this).val('{{ Cache::get('pressure', '') }}');
            }
        });

        /* 去缓存获取温度 */
        $("input[name='temp']").each(function () {
            if ($(this).val() === '') {
                $(this).val('{{ Cache::get('temp', '') }}');
            }
        });
        /* 去缓存获取湿度 */
        $("input[name='hum']").each(function () {
            if ($(this).val() === '') {
                $(this).val('{{ Cache::get('hum', '') }}');
            }
        });
    });

    /*查看上一个 下一个样品*/
    function goto_pre_next(id) {
        window.location.href = "/{{config('constant.name_admin')}}/itemData/index?id=" + id;
    }

    /*选择设备*/
    function checkDev(itemId,obj) {
        let staIds = $(obj).closest('form').find('input[name=station_ids]').val();
        layer_show('检测设备列表', 'station?sample_id='+'{{request()->id}}'+'&item_id=' + itemId+'&staIds='+staIds);
    }

    /*获取绑定的内网项目*/
    function getBindItem(obj,id) {
        ajax('get','bindThirdItem', {'id':id },getBindItemBak,0);
        function getBindItemBak(res){
            if(res){
                $(obj).closest('.item').find('.toBindItemEle').text('已绑定').attr('data-code',res);
            }
        }
    }

    /*绑定内网项目ID*/
    function toBindItem(obj,id) {
        let itemList = bindItems.test_item_list,bindCode = $(obj).data('code');
        let content = '<article class="page-container form" id="formBind">' +
            '<div class="row cl">' +
            '   <label class="form-label col-xs-3 text-r"><b>工器具名称：</b></label>' +
            '   <div class="formControls col-xs-7 ml-10">'+bindItems.device_category_name+'</div>' +
            '</div>' +
            '<div class="row cl mt-10">' +
            '   <label class="form-label col-xs-3 text-r"><b>绑定项目：</b></label>' +
            '   <div class="formControls col-xs-7 ml-10">' +
            '       <select name="third_item_code" class="input-text">' +
            '           <option value="">--请选择--</option>';
        for(let i in itemList){
            let code = itemList[i].test_item_code;
            content += '<option ';
            if(code === bindCode){
                content += ' selected ';
            }
            content += ' value="'+code+'"> '+itemList[i].test_item_name+'</option>';
        }
        content += '</select></div>' +
            '</div>' +
            '<div class="row cl mt-10 text-c">' +
            '   <span class="btn btn-primary radius" onclick="saveBindItem('+id+')">确定</span>' +
            '   <span class="btn btn-warning radius" onclick="saveBindItem('+id+',0)">取消绑定</span>' +
            '   <span class="btn btn-danger radius" onclick="javascript:layer.close(index2);">关闭</span>' +
            '</div>' +
            '</article>';
        index2 = layer.open({
            content: content,
            title: '绑定内网项目',
            type: 1,
            area: ['800px', '600px'],
            scrolling: false,
            closeBtn: 2, //右上角关闭按钮风格  0无,1默认,2
            shadeClose: true, //开启遮罩关闭
        });
    }

    function saveBindItem(id,save=1) {
        let params = {
            'id':id,
            'third_item_code': save == 1 ? $('[name=third_item_code]').val() : '',
        };
        ajax('post','bindThirdItem',params,bindItemBak);
        function bindItemBak(res) {
            if(res === '1'){
                layer.close(index2);
                location.reload();
            }
        }
    }

    function toBindKey(obj) {
        let id = $(obj).data('id'),
            upload_key = $(obj).data('key'),
            upload_unit = $(obj).data('unit'),
            upload_bei = $(obj).data('bei');
        let bindItemEle = $(obj).closest('.info').find('.toBindItemEle'),itemCode = bindItemEle.data('code');
        if('已绑定' !== bindItemEle.text().trim()){
            layer.msg('请先绑定内网项目！');
            return false;
        }
        let itemList = bindItems.test_item_list;
        let content = '<article class="page-container form" id="formBind">' +
            '<div class="row cl">' +
            '   <label class="form-label col-xs-3 text-r"><b>工器具名称：</b></label>' +
            '   <div class="formControls col-xs-7 ml-10">'+bindItems.device_category_name+'</div>' +
            '</div>' +
            '<div class="row cl mt-10">' +
            '   <label class="form-label col-xs-3 text-r"><b>绑定项目：</b></label>' +
            '   <div class="formControls col-xs-7 ml-10">' +
            '       <select name="third_item_code" class="input-text">' +
            '           <option value="">--请选择--</option>';
        let num = 0;
        for(let i in itemList){
            let code = itemList[i].test_item_code;
            content += '<option ';
            if(code === itemCode){
                num = i;
                content += ' selected ';
            }
            content += ' value="'+code+'"> '+itemList[i].test_item_name+'</option>';
        }
        content += '</select></div>' +
            '</div>' +
            '<div class="row cl mt-10">' +
            '   <label class="form-label col-xs-3 text-r"><b>绑定试验数据：</b></label>' +
            '   <div class="formControls col-xs-7 ml-10">' +
            '       <select onchange="chageKey(this)" name="upload_key" class="input-text">' +
            '           <option value="">--请选择--</option>';
        let uploadParams = itemList[num].upload_param;
        for(let j in uploadParams){
            let code = uploadParams[j].key;
            // console.log(uploadParams[j])
            content += '<option data-unit="'+ uploadParams[j].unit +'" ';
            if(code === upload_key){
                content += ' selected ';
            }
            content += ' value="'+code+'"> '+uploadParams[j].title+'</option>';
        }
        content += '</select></div>' +
            '</div>' +
            '<div class="row cl">' +
            '   <label class="form-label col-xs-3 text-r"><b>试验数据单位：</b></label>' +
            '   <div class="formControls col-xs-7 ml-10"><input type="text" class="input-text l" name="upload_unit" value="'+upload_unit+'"></div>' +
            '</div>' +
            '<div class="row cl">' +
            '   <label class="form-label col-xs-3 text-r"><b>试验数据倍数：</b></label>' +
            '   <div class="formControls col-xs-7 ml-10"><input type="text" class="input-text l" name="upload_bei" placeholder="云平台数据是内网数据的多少倍，如果是1倍可不填" value="'+upload_bei+'"></div>' +
            '</div>' +
            '<div class="row cl mt-10 text-c">' +
            '   <span class="btn btn-primary radius" onclick="saveBindKey('+id+')">确定</span>' +
            '   <span class="btn btn-warning radius" onclick="saveBindKey('+id+',0)">取消绑定</span>' +
            '   <span class="btn btn-danger radius" onclick="javascript:layer.close(index2);">关闭</span>' +
            '</div>' +
            '</article>';
        index2 = layer.open({
            content: content,
            title: '绑定内网项目',
            type: 1,
            area: ['800px', '600px'],
            scrolling: false,
            closeBtn: 2, //右上角关闭按钮风格  0无,1默认,2
            shadeClose: true, //开启遮罩关闭
        });
    }

    function chageKey(obj) {
        let unit = $(obj).find('option:checked').data('unit');
        $('[name=upload_unit]').val(unit);
    }

    function saveBindKey(id,save=1) {
        let params = {
            'id':id,
            'upload_key': save == 1 ? $('[name=upload_key]').val() : '',
            'upload_unit': save == 1 ? $('[name=upload_unit]').val() : '',
            'upload_bei': save == 1 ? $('[name=upload_bei]').val() : '',
        }
        ajax('post','bindUploadKey',params,bindKeyBak);
        function bindKeyBak(res) {
            if(res === '1'){
                layer.close(index2);
                location.reload();
            }
        }
    }

</script>
@endsection
